﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Forms;

namespace Client
{
    public partial class AStarForm : Form
    {
        private List<PanelGrid> panelGrid = new List<PanelGrid>();
        
        public AStarForm()
        {
            InitializeComponent();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            
          

            int size_field = (this.panel1.Height - 20) / Tractor.Map.Size;
            foreach (KeyValuePair<string, MapField> field in Tractor.Map.Fields.ToList())
            {
                PanelGrid p = new PanelGrid();

                p.BackColor = field.Value.Color;
                p.Height = size_field;
                p.Width = size_field;
                p.CorX = field.Value.CoordianteX;
                p.CorY = field.Value.CoordianteY;

                p.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                System.Drawing.Point location = new System.Drawing.Point(((p.Height - 1) * p.CorX) + 10, ((p.Width - 1) * (Tractor.Map.Size - p.CorY - 1)) + 10);
                p.Location = location;

                System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
                ToolTip1.SetToolTip(p, "Pozycja: " + (p.CorX + 1) + 'x' + (p.CorY + 1) + Environment.NewLine          
                    + "Koszt przejazdu: " + field.Value.DriveCost + " zł");

                panelGrid.Add(p);
                this.panel1.Controls.Add(p);

                p.Click += new EventHandler(toolStripClick);
               
            }
        }

        void toolStripClick(object sender, EventArgs e)
        {
            Tractor.Map.clearMap();
            Tractor.MainForm.listView1.Items.Clear();
            PanelGrid item = (PanelGrid)sender;
            item.BackColor = Color.Red;

            Tractor.GoalNode = new AStarNode2D(null, null, 0, item.CorX, item.CorY);

            Tractor.MainForm.gridPanel.Close();
            Tractor.Astar();
        }
    }
}
